//index.js
//获取应用实例
const app = getApp()
const url = "https://www.fastmock.site/mock/925fae2205932ec106295492f460736b/hema/goodSorts";
const url2 = "https://www.fastmock.site/mock/925fae2205932ec106295492f460736b/hema/scrollList";
Page({
  data: {
    searchText:"冰饮",
    navList:[],
    todayList:[],
    broadcastText:"盒马云超市来啦！0门槛包邮！山海外环内红红火火恍恍惚惚    "
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.toScrollLeft()
  },
  onLoad:function(options){
    var info = wx.getStorageSync('userInfo')||{}
    console.log(info)
    if(!info.hasOwnProperty('nickName')){
      wx.navigateTo({
        url: '../login/login',
      })
    }
    app.getData(url,(data)=>{
      this.setData({navList:data.data})
    })
    app.getData(url2,(data)=>{
      this.setData({todayList:data.data})
    })
    // this.toScrollLeft()
  },
  to:function(e) {
   var id = e.currentTarget.dataset.index
   wx.reLaunch({
     url: '../classify/classify?id='+id,
   })
  },
  toScrollLeft:function(){
    setInterval(()=>{
      var str = this.data.broadcastText.substring(1)
      // console.log(this.data.broadcastText.charAt(0))
      str = str+ this.data.broadcastText.charAt(0)
      // console.log(str)
      this.setData({broadcastText:str})},300)
    
  }
})
